<template>
  <el-input class="" v-model="filePathStr" placeholder="输入文件路径" />
  <el-input class="" v-model="suffix" placeholder="后缀" />

  <el-button @click="startDeleteFile">开始删除</el-button>

  <div class="console">
    <p v-for="(info, index) in infoList" :key="index">{{ info }}</p>
  </div>
</template>

<script lang="ts">
import { Options, Vue } from "vue-class-component";
import { ElMessage } from "element-plus";
import { getAllFilePath } from "../utils/util";
const fs = window.require("fs");
const path = window.require("path");

const process = window.require("process");
const tinypngwrapper = (window as any).tinypngwrapper;

const electron = window.require("electron");
import robotjs_ipc, {
  ECommonColor,
  View,
  ViewColorFeature,
} from "../utils/robotjs_ipc";

export default class DeleteFile extends Vue {
  infoList: string[] = [];
  filePathStr = "";
  suffix = "";

  async deleteFile(filePath: string) {
    fs.unlink(filePath,function(error: any){
    if(error){
        console.log(error);
        return false;
    }
    console.log('删除文件成功');
})
  }
  async startDeleteFile() {
    if (!fs.existsSync(this.filePathStr)) {
      ElMessage("文件或目录不存在");
      return;
    }

    if (!this.suffix) {
      ElMessage("后缀不能为空");
      return;
    }

    let filePathList: string[] = [];
    getAllFilePath(this.filePathStr, filePathList, this.suffix);
    for (let index = 0; index < filePathList.length; index++) {
      const filePath = filePathList[index];
      await this.deleteFile(filePath);
      this.infoList.unshift(`完成：${filePath}`);
    }
    ElMessage({
      message: "文件删除完成",
      type: "success",
    });
  }
}
</script>

<style scoped>
.console {
  max-height: 150px;
  overflow-y: scroll;
}
.dropActive1 {
  background-color: red;
  border-color: red;
}
</style>

function getAllFilePath() {
  throw new Error("Function not implemented.");
}
